package com.dzt.cloudreader.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.dzt.cloudreader.R;
import com.github.chrisbanes.photoview.PhotoView;

/**
 * Created by M02323 on 2017/12/28.
 */

public class LocalGalleryAdapter extends PagerAdapter {
	private int resId;
	private LayoutInflater inflater;

	public LocalGalleryAdapter(Context context, int resId) {
		this.resId = resId;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return 1;
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		View view = inflater.inflate(R.layout.item_gallery, container, false);
		PhotoView image = view.findViewById(R.id.image);
		if (resId != 0) {
			image.setImageResource(resId);
		}
		//image.setOnPhotoTapListener(ViewBigImageActivity.this);
		container.addView(view, 0);
		return view;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) object);
	}
}
